<#assign ctx = request.contextPath />
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="description" content="${company.introduceContent?if_exists}" />
    <title>${company.introduceTitle?if_exists}</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1, minimum-scale=1" />
    <link rel="stylesheet" href="${ctx}/assets/css/member/a.css">
    <link rel="stylesheet" href="${ctx}/assets/css/member/style.css">
    <script src="${ctx}/assets/js/member/zepto.js"></script>
  </head>
  
  <input type="hidden" id="companyId" name="companyId" value="${company.id}" />
  <input type="hidden" id="id" name="id" value="${passenger.id}" />
  
  <body style="text-align:cente">  
  
  	<div class="container" style="background-image: url('${ctx}/assets/img/member/bg_02.jpg')">
      <div class="box">
        <p>你的好友邀请您</p>
        <h3>体验<span></span></h3>
        <div class="go">
          <input type="number" id="phone1" placeholder="请输入手机号" oninput="if(value.length>11)value=value.slice(0,11)">
          <button type="button" id="sub-phone">马上体验</button>
        </div>
      </div>
    </div>
    
    <div class="container2">
      <div class="box">
        <h2>验证码已发送至</h2>
        <div class="getcode">
          <p id="phone"></p>
          <button type="button" class="get-code" id="get-code-btn">获取验证码</button>
        </div>
        <input type="number" style="border-bottom:1px solid #fe4e4e;border-radius: 0px;" id="code" oninput="if(value.length>4)value=value.slice(0,4)">
        <button type="button" class="sub-code" id="sub-code">免费体验</button>
      </div>
    </div>
    
    <div class="container3 container31" style="padding-bottom:20px">
      <div class="bg-box">
        <div class="code-box">
          <!--<img src="./img/code.jpg">-->
          <#if wxsetting.wxQrCode?? && (wxsetting.wxQrCode?length>0)>
          	<img src="${ctx}/${wxsetting.wxQrCode?if_exists}">
          	<p>长按识别二维码关注公众号</p>
          </#if>
        </div>
          <div class="code-box">
              <!--<img src="./img/code.jpg">-->
          <#if wxsetting.wxSmallQrCode?? && (wxsetting.wxSmallQrCode?length>0)>
          	<img src="${ctx}/${wxsetting.wxSmallQrCode?if_exists}">
          	<p>长按识别二维码关注小程序</p>
          </#if>
          </div>
      </div>
    <div style="background-image: url(${ctx}/assets/img/member/bg_03.png);background-repeat: no-repeat;background-size: cover;padding: 2rem 0;position: fixed;width: 100%;bottom: 0;">
    <div class="app-down" id="ios_down_div">
        <div class="icon" style="background-image: url(${ctx}/assets/img/member/apple_001.png)"></div>
        <#--<div class="text">
          <h3>免费安装</h3>
          <p>ipone版</p>
        </div>-->
      </div>
      <div class="app-down" id="and_down_div">
        <div class="icon" style="background-image: url(${ctx}/assets/img/member/android_001.png)"></div>
      <#--  <div class="text">
          <h3>免费下载</h3>
          <p>Android版</p>
        </div>-->
      </div>
    </div>
    </div>
    
    <div class="modal" id="modal">
      <div class="box">
        <p id="msg"></p>
        <div class="btn">
          <button type="button" id="modal-btn">确认</button>
        </div>
      </div>
    </div>
    
  </body>
  <script>
    function resize() {
      document.documentElement.style.fontSize = document.documentElement.clientWidth / 25 + 'px';
    }
    window.onresize = resize
    
    window.onload = resize
    
    $('.container2, .container3').hide()
    $('#modal').hide()
    $('#and_down_div').hide()
    $('#ios_down_div').hide()
    

    $('#sub-phone').click(function () {
      var phone = $('#phone1').val()
      var isphone=/^[0-9]{1,15}$/;
      if (phone == '' || phone.length != 11 ||!isphone.test(phone)) {
    	  $('#msg').html('手机号错误')
    	  $('#modal').show()
    	  $('#phone1').attr('readonly', true)
    	  return
      }
      $('.container, .container3').hide()
      $('.getcode p').html($('.go input').val())
      $('.container2').show()
      $('#get-code-btn').click()
    })
    
    
    //---------------------------------------------------------------------------------
    
     $('#modal-btn').click(function(){
    	  javascript:$('#modal').hide()
    	   $('#phone1').removeAttr('readonly')
     })
    
    // 获取验证码倒数计时
    function smsOverTime(t){
		var howlong=t;
		
		howlong--;
		$("#get-code-btn").html(howlong);
		
		var timeID = setTimeout("smsOverTime(" + howlong + ")", 1000);
		if (howlong <= 0) {
			clearTimeout(timeID);
			$("#get-code-btn").html("获取验证码");
			$("#get-code-btn").attr("disable", false);
		}
		
	}
    
    // 点击获取验证码
    $('#get-code-btn').click(function () {
    
    	if ($('#get-code-btn').attr("disable") == 'true') {
    		return
    	}
    	
    	// 获取手机号
    	var phone = $('#phone').html();
    	var isphone=/^[0-9]{1,15}$/;
    	if (phone == '' || phone.length != 11 ||!isphone.test(phone)) {
    		$('#msg').html('手机号错误')
    		$('#modal').show()
    		return
    	}
    	
    	// 获取公司ID
    	var companyId = $("#companyId").val()
    	if (companyId == '' || companyId == 0) {
    		$('#msg').html('公司信息错误')
    		$('#modal').show()
    		return
    	}
    	
    	// 获取推荐人ID
    	var introducerId = $("#id").val()
    	if (introducerId == '' || introducerId == 0) {
    		$('#msg').html('用户信息获取失败')
    		$('#modal').show()
    		return
    	}
    	
    	// 发送验证码
    	$('.get-code').attr("disable", true);
    	$.get('${ctx}/member/api/rest/v3/smsQrCode',{'companyId':companyId,'phone':phone,'introducerId':introducerId},function(result){
			if(result.success){
				smsOverTime(120);

			} else {
				
				if(result.errorcode=="0"){
				
					smsOverTime(result.object);
					
				} else if (result.errorcode=="1") {
					$('#msg').html('发送失败')
    				$('#modal').show()
					$(".get-code").attr("disable", false);
				}
			}
		}, 'json');
    })
    
    // 提交验证验证码，并跳转下载页面
    $('#sub-code').click(function () {
    	if ($(".sub-code").attr("disable") == "true") {
    		return
    	}
    	var phone = $('#phone').html();
    	var isphone=/^[0-9]{1,15}$/;
    	if (phone == '' || phone.length != 11 ||!isphone.test(phone)) {
    		$('#msg').html('手机号错误')
    		$('#modal').show()
    		return
    	}
    	
    	var code = $("#code").val();
		if (code == "" || code.length != 4){
			$('#msg').html('验证码错误')
    		$('#modal').show()
    		return
		}
		
		var id = $("#id").val()
    	if (id == '' || id == 0) {
    		$('#msg').html('用户信息获取失败')
    		$('#modal').show()
    		return
    	}
		
		var params = {phone:phone,code:code,id:id}
		
		$(".sub-code").attr("disable", true);
		$.post('${ctx}/member/api/rest/v3/downloadShareQrCode',params,function(data){
			if(data.success){
				zdxz(data.map.androidUrl,data.map.iosUrl);
			} else {
				$(".sub-code").attr("disable", false);
				$('#msg').html(data.message)
    			$('#modal').show()
			}
		}, 'json');
    })
    
   function is_weixin(){
		var ua = navigator.userAgent.toLowerCase();
		if(ua.match(/MicroMessenger/i)=="micromessenger") {
			return true;
		} else {
			return false;
		}
	}
	
	function is_qq(){
		var ua = navigator.userAgent.toLowerCase();
		if(ua.match(/MQQBrowser/i)=="mqqbrowser") {
			return true;
		} else {
			return false;
		}
	}
			
    var browser = {
        versions: function() {
            var u = navigator.userAgent, app = navigator.appVersion;
            return {//移动终端浏览器版本信息 
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }
    
    
    function zdxz(androidUrl, iosUrl){
		$('.container2, .container1').hide()
		$('.container3').show()
 		if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
			
			if (androidUrl && androidUrl != "") {
				$("#and_down_div").show();
				$("#and_down_div").click(function () {
					if(is_weixin()){
						window.location="${ctx}/member/api/rest/v3/appXiazai";
			 		} else {
			 			$('#msg').html('操作成功,准备下载客户端')
						$('#modal').show()
						window.location = androidUrl;
			 		}
				})
			}
			
			if (iosUrl && iosUrl != "") {
				$("#ios_down_div").show();
				$("#ios_down_div").click(function () {
					if(is_weixin()){
						window.location="${ctx}/member/api/rest/v3/appXiazai";
			 		} else {
			 			$('#msg').html('操作成功,准备下载客户端')
						$('#modal').show()
						window.location = iosUrl
			 		}
				})
			}
  			
  			
		} else if (browser.versions.android) {
			
			if (androidUrl && androidUrl != "") {
				$("#and_down_div").show();
				$("#and_down_div").click(function () {
					if(is_weixin()){
						window.location="${ctx}/member/api/rest/v3/appXiazai";
			 		} else {
			 			$('#msg').html('操作成功,准备下载客户端')
						$('#modal').show()
						window.location = androidUrl;
			 		}
				})
			}
			
			if (iosUrl && iosUrl != "") {
				$("#ios_down_div").show();
				$("#ios_down_div").click(function () {
					if(is_weixin()){
						window.location="${ctx}/member/api/rest/v3/appXiazai";
			 		} else {
			 			$('#msg').html('操作成功,准备下载客户端')
						$('#modal').show()
						window.location = iosUrl
			 		}
				})
			}
		}
	}
    
  </script>
</html>
